﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace DataBaseApi
{
  public   class API
    {
        public bool IsRegisters(string VerifString)
        {
            try
            {
                HttpClient httpClient = new HttpClient();
                HttpResponseMessage response = httpClient.GetAsync("http://101.201.46.190/selfhost/api/user/IsKeyOrTrue?Verify=" + VerifString + "").Result ;
                bool user = response.Content.ReadAsAsync<bool>().Result;
                return user;
            }
            catch(Exception ex) 
            {
                string msg = ex.Message;
                return false;
            }
           
        }

        public async Task<bool> IsRegister(string VerifString)
        {
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.GetAsync("http://101.201.46.190/selfhost/api/user/IsKeyOrTrue?Verify=" + VerifString + "");
            bool res = response.Content.ReadAsAsync<bool>().Result;
            return res;
        }


        public async Task <bool> SaveHistory(ControlHistory  CH)
        {
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response =await  httpClient.PostAsJsonAsync<ControlHistory>("http://101.201.46.190/selfhost/api/ControlHistory/Add", CH );
            bool resbool = response.Content.ReadAsAsync<bool>().Result;
            return resbool;
        }

        public async Task<Result> AutoAdd(JSON_CMDModel CH)
        {
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.PostAsJsonAsync<JSON_CMDModel>("http://101.201.46.190/selfhost/api/AutoConfig/AutoAdd", CH);
            Result resbool = response.Content.ReadAsAsync<Result>().Result;
            return resbool;
        }
    }
}
